package cn.wellwan.observer.utilobserver;

import java.util.Observable;
import java.util.Observer;

/**
 * creator: maokai
 * on: 2018/3/27
 * description: 目前状况布告板
 */
public class CurrentConditionsDisplay implements Observer, DisplayElement {

    private float temperature;
    private float humidity;
    private Observable observable;

    public CurrentConditionsDisplay (Observable observable) {
        this.observable = observable;
        //注册主题
        observable.addObserver(this);
    }

    @Override
    public void display () {
        System.out.println( "temperature--> "+ this.temperature);
        System.out.println( "humidity--> "+ this.humidity);
    }

    @Override
    public void update (Observable o , Object arg) {
        if (o instanceof WeatherData) {
            WeatherData weatherData = (WeatherData) o;
            this.temperature = weatherData.getTemperature();
            this.humidity = weatherData.getHumidity();
            this.display();
        }
    }
}
